package ${corePackageStr};

import com.differ.jackyun.framework.component.basic.interceptor.ServiceException;
import com.differ.jackyun.framework.component.utils.id.IdWorkerUtil;
import com.differ.jackyun.frame.businesscommondb.core.ICommonDataCore;
import com.differ.jackyun.frame.base.enums.CommonResponseCodesEnum;
import com.differ.jackyun.frame.base.util.Util;
import com.differ.jackyun.frame.businesscommondb.dao.ICommonDataDao;
import ${daoPackageStr}.${className};
import ${filterPackageStr}.${filterName};
import ${filterPackageStr}.${resultName};
import ${entityPackageStr}.${entityClassName};
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Objects;

/**
 * ${entityDesc} - CORE
 *
 * @author LiYuan
 * @since  ${time}
 */
@Component
public class ${coreName} implements ICommonDataCore<${filterName}, ${entityClassName}, ${resultName}> {
    @Autowired
    private ${className} ${classNameLow};

     /**
      * 获取对应dao
      *
      * @return 对应dao
      */
     @Override
     public ICommonDataDao getCommonDataDao() {
         return this.${classNameLow};
     }

    /**
     * 添加操作 - 批量数据校验
     *
     * @param entityList 实体List
     */
    @Override
    public void checkDataForAdd(List<${entityClassName}> entityList) {
        // 先调用（父类）接口的校验
        ICommonDataCore.super.checkDataForAdd(entityList);

        // 业务代码
        entityList.forEach(e -> {
            // 添加id
            e.setId(IdWorkerUtil.getId());

            // 设置默认值
            Util.checkProperty(e);
        });

    }

    /**
     * 修改操作 - 批量数据校验
     *
     * @param entityList 实体List
     */
    @Override
    public void checkDataForUpdate(List<${entityClassName}> entityList) {
        // 先调用（父类）接口的校验
        ICommonDataCore.super.checkDataForUpdate(entityList);

        // 业务代码
        for (${entityClassName} e : entityList) {
            if (Objects.isNull(e.getId())) {
                throw new ServiceException(CommonResponseCodesEnum.WARN_ID_IS_EMPTY);
            }
        }
    }
}